package com.example.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;

public class InternalPage extends AnyPage {

    @FindBy(xpath = "//header//nav//a[contains(@href, '/?logout')]")
    public WebElement menuLogoutLink;

    @FindBy(xpath = "//header//nav//a[contains(@href, '/?go=profile')]")
    public WebElement menuMyProfileLink;

    @FindBy(xpath = "//header//nav//a[contains(@href, '/?go=users')]")
    public WebElement menuUserManagementLink;

    @FindBy(xpath = "//nav/ul/li[1]/a")
    public WebElement menuHomeLink;

    public boolean isOnThisPage() {
        return menuLogoutLink.isDisplayed();
    }

    public UserManagementPage goToUserManagementPage() {
        menuUserManagementLink.click();
        return MyPageFactory.getPage(driver, UserManagementPage.class);
    }

    public HomePage goToHomePage() {
        menuHomeLink.click();
        return MyPageFactory.getPage(driver, HomePage.class);
    }

    public FilmsPage goToFilmsPage() {
        menuHomeLink.click();
        return MyPageFactory.getPage(driver, FilmsPage.class);
    }

    public LoginPage logout() {
        menuLogoutLink.click();
        wait_().until(alertIsPresent()).accept();
        return MyPageFactory.getPage(driver, LoginPage.class);
    }

    @Override
    void tryToOpen() {
        MyPageFactory.getPage(driver, LoginPage.class).loginAs("admin", "admin");
    }


}
